package com.atguigu.comparable2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/*
    需求 ：对总流量进行排序。

    FlowBean必须为key,因为只能对key进行排序
 */
public class FlowMapper extends Mapper<LongWritable, Text,FlowBean,Text> {
    //封装的key
    private FlowBean outKey = new FlowBean();
    //封装的value
    private Text outValue = new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.将value转成String
        String line = value.toString();
        //2.切割数据
        String[] phoneInfo = line.split("\t");
        //3.封装
        outKey.setUpFlow(Long.parseLong(phoneInfo[1]));
        outKey.setDownFlow(Long.parseLong(phoneInfo[2]));
        outKey.setSumFlow(Long.parseLong(phoneInfo[3]));

        outValue.set(phoneInfo[0]);
        //4.写出K,V
        context.write(outKey,outValue);
    }
}
